#include"game.h"
#include<stdio.h>

void Initboard (char board [ROW][COL],int row,int col)
{
    for (int i=0;i<row;i++)
    {
        for (int j=0;j<col;j++)
        {
            board[i][j]=' ';
        }
    }
}
void print (char board [ROW][COL],int row,int col)
{
   for (int i=0;i<row;i++)
   {  for (int j=0;j<col;j++)
     {
        printf(" %c ",board [i][j]);
        if (j<col-1)
          printf("|");
     }
     printf("\n");
     if (i<row-1)
     {
      for (int a=0;a<col;a++)
       {
        printf("---");
        if (a<col-1)
          printf("|");
       }
     printf("\n");
     }
   }
}
void playermove (char board [ROW][COL],int row,int col)
{
  int x,y;
  printf("玩家走:");
  for (int i=0;;i++)
   {
      scanf("%d %d",&x,&y);
      if (x>=1&&x<=row&&y>=1&&y<=col)
      {
        if (board[x-1][y-1]==' ')
        {
          board [x-1][y-1]='*';
          break;
        }
        else 
        printf ("坐标占用，请重新输入");
      }  
      else 
        printf("输入错误，请重新输入"); 
   }
}
void computermove (char board [ROW][COL],int row,int col)
{
  printf("贾哥走:\n");
  while (1)
  {
    int x=rand()%3;
    int y=rand()%3;
    if (board [x][y]==' ')
   {
     board[x][y]='#';
     break;
   }
  }
}
char  Iswin (char board[ROW][COL],int row,int col)
{
  for (int i=0;i<row;i++)
  {
    if (board[i][0]==board[i][1]&&board[i][1]==board[i][2]&&board[i][0]!=' ')
    {
      return board[i][0];
      break;
    }
  }
  for (int j=0;j<col;j++)
  {
    if (board[0][j]==board[1][j]&&board[1][j]==board[2][j]&&board[0][j]!=' ')
     {
      return board[0][j];
      break;
     }
  }
  if (board[0][0]==board[1][1]&&board[1][1]==board[2][2]&&board[0][0]!=' ')
     return board[0][0]; 
  if (board[0][2]==board[1][1]&&board[1][1]==board[2][0]&&board[1][1]!=' ')
     return board[0][0]; 
  for (int a=0;a<row;a++)
  {
    for (int b=0;b<col;b++)
     {
      if (board[a][b]!=' ')
      return 'c';
     }
  }
  return 'Q';

}